from core.logger import log
from db.models.wx_friends import WxFriendsCreate
from services.wx_friends_service import create_wx_friends
from utils.qw_util import get_qw_access_token
from utils.result import Result
from fastapi import APIRouter

from utils.sender_tools import SenderTools

router = APIRouter()

@router.post("/wx_friends")
async def add_wx_friends(wx_fd_params: WxFriendsCreate):
    result = await create_wx_friends(wx_fd_params.auth_key, wx_fd_params.device_id)
    return result



@router.get("/www")
async def f(to_user, open_kfid):
    """
    to_user = wmCnFDKgAATHYmGoqQCpwZQQZH4A3kqg
    open_kfid = wkCnFDKgAA_voRFXny45Ck7CqozrLA_g

    link = "https://work.weixin.qq.com/ca/cawcde72304ee0ca45"
    """
    s = SenderTools()
    access_token = await get_qw_access_token()
    res = s.send_qw_business_card(access_token = access_token, to_user = to_user, open_kfid = open_kfid, card_link = "https://work.weixin.qq.com/ca/cawcde0f6a79b604e9")
    log.info( res)
    return  res